<?php
class Provider_model extends CI_Model
{
	public $tbl = 'provider';

	public function __contruct()
	{
		parent::__construct();	
	}

	public function All($companyId)
	{
		$this->db->where('CompanyId', $companyId);
		$query = $this->db->get($this->tbl);
		
		return $query->result();
	}

	public function Add($companyId)
	{
		$data = array(
			'Name' => $this->input->post('Name'),
			'Address' => $this->input->post('Address'),
			'Phone1' => $this->input->post('Phone1'),
			'Phone2' => $this->input->post('Phone2'),
			'CompanyId' => $companyId
			);

		return $this->db->insert($this->tbl, $data);
	}

	public function Active($providerId)
	{
		$queryString = "UPDATE provider
						SET IsActive = CASE WHEN IsActive = 1 THEN 0 ELSE 1 END
						WHERE id = $providerId";
		$query = $this->db->query($queryString);		
	}	
}
?>